/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlet;

import java.awt.BasicStroke;
import java.awt.Color;  
import java.awt.Dimension;  
import java.awt.Font;  
import java.awt.GradientPaint;  
import java.awt.Image;  
import java.awt.Point;  
import java.io.File;  
import java.io.IOException;  
import java.io.OutputStream;  
import java.text.DecimalFormat;  
  
import javax.servlet.ServletException;  
import javax.servlet.annotation.WebServlet;  
import javax.servlet.http.HttpServlet;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
import org.jfree.chart.ChartFactory;
  
import org.jfree.chart.ChartPanel;  
import org.jfree.chart.ChartUtilities;  
import org.jfree.chart.JFreeChart;  
import org.jfree.chart.plot.dial.DialBackground;  
import org.jfree.chart.plot.dial.DialPlot;  
import org.jfree.chart.plot.dial.DialTextAnnotation;  
import org.jfree.chart.plot.dial.StandardDialFrame;  
import org.jfree.chart.plot.dial.StandardDialRange;  
import org.jfree.chart.plot.dial.StandardDialScale;  
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.DefaultValueDataset;  
import org.jfree.ui.GradientPaintTransformType;  
import org.jfree.ui.StandardGradientPaintTransformer;  
import repositorio.RepositorioMegaSenaBD;
  
@WebServlet("/ChartServlet1")  
public class ChartServlet1 extends HttpServlet {  
    private static final long serialVersionUID = 1L;  
  
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
       response.setContentType("image/png");

		OutputStream outputStream = response.getOutputStream();

		JFreeChart chart = getChart();
		int width = 500;
		int height = 350;
		ChartUtilities.writeChartAsPNG(outputStream, chart, width, height);

	}

	public JFreeChart getChart() {
                RepositorioMegaSenaBD mega = new RepositorioMegaSenaBD();
		DefaultPieDataset dataset = new DefaultPieDataset();
		dataset.setValue("04", mega.procuraNumero(4));
		dataset.setValue("02", mega.procuraNumero(2));
		dataset.setValue("08", mega.procuraNumero(8));
                dataset.setValue("05", mega.procuraNumero(5));
                dataset.setValue("25", mega.procuraNumero(25));
                dataset.setValue("60", mega.procuraNumero(60));

		boolean legend = true;
		boolean tooltips = false;
		boolean urls = false;

		JFreeChart chart = ChartFactory.createPieChart("Sorte", dataset, legend, tooltips, urls);

		chart.setBorderPaint(Color.GREEN);
		chart.setBorderStroke(new BasicStroke(5.0f));
		chart.setBorderVisible(true);

		return chart;
	} 
}  